
use "V-Dem-CY-Core-v12.dta", clear

*creating pais variable for matching (Belize not in v-dem)
gen pais=.
	replace pais=1 if country_name=="Mexico"
	replace pais=2 if country_name=="Guatemala"
	replace pais=3 if country_name=="El Salvador"
	replace pais=4 if country_name=="Honduras"
	replace pais=5 if country_name=="Nicaragua"
	replace pais=6 if country_name=="Costa Rica"
	replace pais=7 if country_name=="Panama"
	replace pais=8 if country_name=="Colombia"
	replace pais=9 if country_name=="Ecuador"
	replace pais=10 if country_name=="Bolivia"
	replace pais=11 if country_name=="Peru"
	replace pais=12 if country_name=="Paraguay"
	replace pais=13 if country_name=="Chile"
	replace pais=14 if country_name=="Uruguay"
	replace pais=15 if country_name=="Brazil"
	replace pais=16 if country_name=="Venezuela"
	replace pais=17 if country_name=="Argentina"
	replace pais=21 if country_name=="Dominican Republic"
	replace pais=22 if country_name=="Haiti"
	replace pais=23 if country_name=="Jamaica"
	replace pais=24 if country_name=="Guyana"
drop if missing(pais)

*creating year-specific variables for clientelism
sum v2elvotbuy v2dlencmps v2psprlnks //-3.5~3 
tab country_name year if year>2010 & year<2015 & !missing(pais, v2xnp_client), mis // all years
tab country_name year if year>2010 & year<2015 & !missing(pais, v2dlencmps), mis // all years
tab country_name year if year>2010 & year<2015 & !missing(pais, v2psprlnks), mis // all years
tab country_name year if year>2010 & year<2015 & !missing(pais, v2elvotbuy), mis // only some years

gen particular2014=.
		replace particular2014=v2dlencmps if year==2014
		
gen clientelist2014=.
		replace clientelist2014=v2psprlnks if year==2014
	
gen vbuy2014=.
	tab country_name year if year>2010 & year<2015 & !missing(pais, v2elvotbuy)		
		replace vbuy2014=v2elvotbuy if year==2014
		replace vbuy2014=v2elvotbuy if year==2013 & inlist(country_name, "Argentina", "Chile", "Ecuador", "Honduras", "Paraguay", "Venezuela")
		replace vbuy2014=v2elvotbuy if year==2012 & inlist(country_name, "Dominican Republic", "Chile", "Mexico")
		replace vbuy2014=v2elvotbuy if year==2011 & inlist(country_name, "Guatemala", "Guyana", "Haiti", "Jamaica", "Nicaragua", "Peru")
		
rescale vbuy2014 1 0
rescale particular2014 1 0
rescale clientelist2014 1 0	

*creating year-specific variables for election irregularities
sum v2elirreg v2elintim v2elpeace v2elfrfair // other voting irregularities, govt intimidation, electoral violence, free & fair elections (-4.6~2.7)
tab country_name year if year>2010 & year<2015 & !missing(pais, v2elirreg), mis // only some years 
	gen irreg2014=.	
		replace irreg2014=v2elirreg if year==2014
		replace irreg2014=v2elirreg if year==2013 & inlist(country_name, "Argentina", "Chile", "Ecuador", "Honduras", "Paraguay", "Venezuela")
		replace irreg2014=v2elirreg if year==2012 & inlist(country_name, "Dominican Republic", "Chile", "Mexico")
		replace irreg2014=v2elirreg if year==2011 & inlist(country_name, "Guatemala", "Guyana", "Haiti", "Jamaica", "Nicaragua", "Peru")
tab country_name year if year>2010 & year<2015 & !missing(pais, v2elintim), mis // some years 
	gen intimidate2014=.
		replace intimidate2014=v2elintim if year==2014
		replace intimidate2014=v2elintim if year==2013 & inlist(country_name, "Argentina", "Chile", "Ecuador", "Honduras", "Paraguay", "Venezuela")
		replace intimidate2014=v2elintim if year==2012 & inlist(country_name, "Dominican Republic", "Chile", "Mexico")
		replace intimidate2014=v2elintim if year==2011 & inlist(country_name, "Guatemala", "Guyana", "Haiti", "Jamaica", "Nicaragua", "Peru")
tab country_name year if year>2010 & year<2015 & !missing(pais, v2elpeace), mis // some years 
	gen violent2014=.
		replace violent2014=v2elpeace if year==2014
		replace violent2014=v2elpeace if year==2013 & inlist(country_name, "Argentina", "Chile", "Ecuador", "Honduras", "Paraguay", "Venezuela")
		replace violent2014=v2elpeace if year==2012 & inlist(country_name, "Dominican Republic", "Chile", "Mexico")
		replace violent2014=v2elpeace if year==2011 & inlist(country_name, "Guatemala", "Guyana", "Haiti", "Jamaica", "Nicaragua", "Peru")
tab country_name year if year>2010 & year<2015 & !missing(pais, v2elfrfair), mis // some years
	gen frfair2014=.
		replace frfair2014=v2elfrfair if year==2014
		replace frfair2014=v2elfrfair if year==2013 & inlist(country_name, "Argentina", "Chile", "Ecuador", "Honduras", "Paraguay", "Venezuela")
		replace frfair2014=v2elfrfair if year==2012 & inlist(country_name, "Dominican Republic", "Chile", "Mexico")
		replace frfair2014=v2elfrfair if year==2011 & inlist(country_name, "Guatemala", "Guyana", "Haiti", "Jamaica", "Nicaragua", "Peru")
rescale irreg2014 1 0
rescale intimidate2014 1 0
rescale violent2014 1 0
rescale frfair2014 1 0


drop if missing(vbuy2014) & missing(particular2014) & missing(clientelist2014) & missing(irreg2014) & missing(intimidate2014) & missing(violent2014) & missing(frfair2014)
		

*creating dataset 
keep country_name pais vbuy2014 particular2014 clientelist2014 irreg2014 intimidate2014 violent2014 frfair2014
collapse vbuy2014 particular2014 clientelist2014 irreg2014 intimidate2014 violent2014 frfair2014, by(country_name pais)
gen wave=2014
rename vbuy2014 vbuy
	rename particular2014 particular
	rename clientelist2014 clientelist
	rename irreg2014 irregularities
	rename intimidate2014 govtintimidation
	rename violent2014 elviolence
	rename frfair2014 freefair
lab var vbuy "Prevalence of Vote Buying (Vdem)"
lab var particular "Prevalence of Particularistic Goods (Vdem)"
lab var clientelist "Prevalence of Clientelistic Party Linkages (Vdem)"
save "vdem.dta", replace

	